﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccessLayer.Properties;
using IMModel.Domain;

namespace DataAccessLayer.Admin.Copy.UniversityStruct
{
    public class DepartmentCopy : ICopy
    {
        public int Copy(int IDCopiedObject, int? IDParentObject, int fromIDTerm, int toIDTerm)
        {
            using (IMModel.Domain.IMDataDataContext db = new IMModel.Domain.IMDataDataContext(Settings.Default.IndexMarkConnectionString))
            {
                DepartmentTerm old = db.DepartmentTerms.Single(s => s.IDDepartmentTerm == IDCopiedObject);

                DepartmentTerm _new = new DepartmentTerm
                {
                    IDDepartment = old.IDDepartment,
                    IDTerm = toIDTerm,
                    IDParentDepartmentTerm = IDParentObject
                };
                db.DepartmentTerms.InsertOnSubmit(_new);
                db.SubmitChanges();

                return _new.IDDepartmentTerm;
            }
        }
    }
}
